fn main() {
    let mut count = 0u32;
    println!("Let's count until infinity!");
    // 无限循环
    loop {
        count += 1;
        if count == 3 {
            println!("three");
            // 跳过这次迭代的剩下内容
            continue;
        }
        println!("{}", count);
        if count == 5 {
            println!("OK, that's enough");
            // 退出循环
            break;
        }
    }

    // 嵌套循环 & 标签
    println!();
    'outer: loop {
        println!("Entered the outer loop");
        'inner: loop {
            println!("Entered the inner loop");
            // 这只是中断内部的循环
            //break;
            // 这会中断外层循环
            break 'outer;
        }
        println!("This point will never be reached");
    }
    println!("Exited the outer loop");

    // 从 loop 循环中返回，
    // 将返回值放在 break 之后，它就会被 loop 表达式返回
    let mut counter = 0;
    let result = loop {
        counter += 1;
        if counter == 10 {
            break counter * 2;
        }
    };
    assert_eq!(result, 20);
}
